Los datos han sido sacados de kaggle , dejo el link a continuacion para poder ver el contenido original y consultarlo en caso de duda. https://www.kaggle.com/datasets/paradisejoy/top-hits-spotify-from-20002019
datos_spotify<-read.csv("songs_normalize.csv",sep=",",header=TRUE)
head(datos_spotify,5)
## artist song duration_ms explicit year popularity
## 1 Britney Spears Oops!...I Did It Again 211160 False 2000 77
## 2 blink-182 All The Small Things 167066 False 1999 79
## 3 Faith Hill Breathe 250546 False 1999 66
## 4 Bon Jovi It's My Life 224493 False 2000 78
## 5 *NSYNC Bye Bye Bye 200560 False 2000 65
## danceability energy key loudness mode speechiness acousticness
## 1 0.751 0.834 1 -5.444 0 0.0437 0.3000
## 2 0.434 0.897 0 -4.918 1 0.0488 0.0103
## 3 0.529 0.496 7 -9.007 1 0.0290 0.1730
## 4 0.551 0.913 0 -4.063 0 0.0466 0.0263
## 5 0.614 0.928 8 -4.806 0 0.0516 0.0408
## instrumentalness liveness valence tempo genre
## 1 1.77e-05 0.3550 0.894 95.053 pop
## 2 0.00e+00 0.6120 0.684 148.726 rock, pop
## 3 0.00e+00 0.2510 0.278 136.859 pop, country
## 4 1.35e-05 0.3470 0.544 119.992 rock, metal
## 5 1.04e-03 0.0845 0.879 172.656 pop
spotify<-datos_spotify[,c("artist","song","duration_ms","explicit","year","popularity","tempo","genre","danceability","speechiness","energy")]
head(spotify,5)
## artist song duration_ms explicit year popularity
## 1 Britney Spears Oops!...I Did It Again 211160 False 2000 77
## 2 blink-182 All The Small Things 167066 False 1999 79
## 3 Faith Hill Breathe 250546 False 1999 66
## 4 Bon Jovi It's My Life 224493 False 2000 78
## 5 *NSYNC Bye Bye Bye 200560 False 2000 65
## tempo genre danceability speechiness energy
## 1 95.053 pop 0.751 0.0437 0.834
## 2 148.726 rock, pop 0.434 0.0488 0.897
## 3 136.859 pop, country 0.529 0.0290 0.496
## 4 119.992 rock, metal 0.551 0.0466 0.913
## 5 172.656 pop 0.614 0.0516 0.928
Voy a cambiar el nombre de las columnas mas dudosas y a pasarlo todo al español, también aprovecho y corrijo la columna de milisegundos y lo paso a una unidad mejor interpretable como la de segundos.
colnmes<-c("Artista","Cancion","Duracion_segundos","Contenido_explicito","Año","Popularidad_cancion","Tempo_BPM","Genero","Capacidad_ser_bailada","Presencia_de_palabras","Intensidad_Actividad")
colnames(spotify)<-colnmes
spotify$Duracion_segundos<-spotify$Duracion_segundos/1000
head(spotify,5)
## Artista Cancion Duracion_segundos Contenido_explicito
## 1 Britney Spears Oops!...I Did It Again 211.160 False
## 2 blink-182 All The Small Things 167.066 False
## 3 Faith Hill Breathe 250.546 False
## 4 Bon Jovi It's My Life 224.493 False
## 5 *NSYNC Bye Bye Bye 200.560 False
## Año Popularidad_cancion Tempo_BPM Genero Capacidad_ser_bailada
## 1 2000 77 95.053 pop 0.751
## 2 1999 79 148.726 rock, pop 0.434
## 3 1999 66 136.859 pop, country 0.529
## 4 2000 78 119.992 rock, metal 0.551
## 5 2000 65 172.656 pop 0.614
## Presencia_de_palabras Intensidad_Actividad
## 1 0.0437 0.834
## 2 0.0488 0.897
## 3 0.0290 0.496
## 4 0.0466 0.913
## 5 0.0516 0.928
Seleccionando los 5 primeros registros para ver la forma que toma el dataset.
numero_canciones_x_genero<-spotify %>% select(Genero) %>% group_by(Genero) %>% summarise(numero_de_canciones=n()) %>% arrange(desc(numero_de_canciones))
numero_canciones_x_genero
## # A tibble: 59 × 2
## Genero numero_de_canciones
## <chr> <int>
## 1 pop 428
## 2 hip hop, pop 277
## 3 hip hop, pop, R&B 244
## 4 pop, Dance/Electronic 221
## 5 pop, R&B 178
## 6 hip hop 124
## 7 hip hop, pop, Dance/Electronic 78
## 8 rock 58
## 9 rock, pop 43
## 10 Dance/Electronic 41
## # … with 49 more rows
Aquí las tenemos todas las canciones agrupadas por género y ordenadas de mayor a menor.
ggplot(head(numero_canciones_x_genero,10),aes(x=Genero,y=numero_de_canciones,fill=Genero))+
geom_col()+theme(axis.text.x = element_blank())+ggtitle("Top 10 géneros de las canciones mas escuchadas")
Aquí vemos como los géneros:pop,(hip hop,pop),(hip hop, pop, R&B),(pop, Dance/Electronic),(pop, R&B),(hip hop), (hip hop, pop, Dance/Electronic),rock,(rock, pop),(Dance/Electronic). Destacando por encima de todos el pop.
numero_canciones_año<-spotify %>% select(Año) %>% group_by(Año) %>% summarise(numero_de_canciones=n()) %>% arrange(Año)
ggplot(numero_canciones_año,aes(x=Año,y=numero_de_canciones,fill=Año))+
geom_line()+theme(axis.text.x = element_text(angle = 45, hjust = 1))+ggtitle("Número de canciones por año")
Vemos como antes del 2000 hay pocos registros y por eso hay una gran pendiente , y lo mismo pasa en el 2020 que es cuando se dejaron de recoger datos en este top. Aparte de esto podemos observar como en el periodo 2010-2013 hay una gran actividad y se generaron muchas de las canciones mas escuchadas.
Numero_veces_artista<-spotify %>% select(Artista) %>% group_by(Artista) %>% summarise(Numero_de_canciones=n()) %>% arrange(desc(Numero_de_canciones))
Numero_veces_artista$Diferencia_vs_media<-Numero_veces_artista$Numero_de_canciones-mean(Numero_veces_artista$Numero_de_canciones)
Numero_veces_artista
## # A tibble: 835 × 3
## Artista Numero_de_canciones Diferencia_vs_media
## <chr> <int> <dbl>
## 1 Rihanna 25 22.6
## 2 Drake 23 20.6
## 3 Eminem 21 18.6
## 4 Calvin Harris 20 17.6
## 5 Britney Spears 19 16.6
## 6 David Guetta 18 15.6
## 7 Chris Brown 17 14.6
## 8 Kanye West 17 14.6
## 9 Beyoncé 16 13.6
## 10 Katy Perry 16 13.6
## # … with 825 more rows
Aquí vemos como los artistas mas escuchados estan muy por encima de la media de canciones compuestas (Alrededor de 12) que entraron en el top.Todos son conocidos mundialmmente y en el top 10 no parece haber ninguna sorpresa.A continuacion vamos a mostrar a los 20 artistas con mas apariciones.
top20<-head(Numero_veces_artista,20)
pie(top20$Numero_de_canciones, clockwise = TRUE, labels = top20$Artista)
title("Top 20 artistas con mas canciones en el top")
baile<-spotify %>% select(Artista,Cancion,Año,Capacidad_ser_bailada,Popularidad_cancion) %>% group_by(Capacidad_ser_bailada) %>% arrange(desc(Capacidad_ser_bailada))
head(baile,10)
## # A tibble: 10 × 5
## # Groups: Capacidad_ser_bailada [8]
## Artista Cancion Año Capacidad_ser…¹ Popul…²
## <chr> <chr> <int> <dbl> <int>
## 1 Timbaland Give It To Me 2007 0.975 70
## 2 Kelis Trick Me 2003 0.97 63
## 3 Missy Elliott 4 My People (feat. Eve) 2001 0.969 49
## 4 Justin Timberlake SexyBack (feat. Timbaland) 2006 0.967 78
## 5 Ciara Get Up (feat. Chamillionaire) 2006 0.964 59
## 6 Nicki Minaj Anaconda 2014 0.964 66
## 7 Eminem Shake That 2005 0.963 74
## 8 Lil Baby Yes Indeed 2018 0.963 79
## 9 Sugababes Push The Button 2005 0.962 64
## 10 Nelly Hot In Herre 2002 0.956 75
## # … with abbreviated variable names ¹Capacidad_ser_bailada,
## # ²Popularidad_cancion
Aquí vemos como las canciones mas bailables no son las mas populares.
canciones_mas_populares<-spotify %>% select(Artista,Cancion,Popularidad_cancion) %>% group_by(Popularidad_cancion) %>% arrange(desc(Popularidad_cancion))
canciones_mas_populares
## # A tibble: 2,000 × 3
## # Groups: Popularidad_cancion [76]
## Artista Cancion Popularidad_cancion
## <chr> <chr> <int>
## 1 The Neighbourhood Sweater Weather 89
## 2 Tom Odell Another Love 88
## 3 Eminem Without Me 87
## 4 Eminem The Real Slim Shady 86
## 5 WILLOW Wait a Minute! 86
## 6 Billie Eilish lovely (with Khalid) 86
## 7 Billie Eilish lovely (with Khalid) 86
## 8 Eminem 'Till I Collapse 85
## 9 Bruno Mars Locked out of Heaven 85
## 10 Bruno Mars Locked out of Heaven 85
## # … with 1,990 more rows
beats<-spotify %>% select(Artista,Cancion,Popularidad_cancion,Tempo_BPM) %>% group_by(Popularidad_cancion) %>% arrange(desc(Popularidad_cancion))
beats
## # A tibble: 2,000 × 4
## # Groups: Popularidad_cancion [76]
## Artista Cancion Popularidad_cancion Tempo_BPM
## <chr> <chr> <int> <dbl>
## 1 The Neighbourhood Sweater Weather 89 124.
## 2 Tom Odell Another Love 88 123.
## 3 Eminem Without Me 87 112.
## 4 Eminem The Real Slim Shady 86 105.
## 5 WILLOW Wait a Minute! 86 101.
## 6 Billie Eilish lovely (with Khalid) 86 115.
## 7 Billie Eilish lovely (with Khalid) 86 115.
## 8 Eminem 'Till I Collapse 85 171.
## 9 Bruno Mars Locked out of Heaven 85 144.
## 10 Bruno Mars Locked out of Heaven 85 144.
## # … with 1,990 more rows
modelo_beats<-lm(Popularidad_cancion~Tempo_BPM,data = beats)
summary(modelo_beats)
##
## Call:
## lm(formula = Popularidad_cancion ~ Tempo_BPM, data = beats)
##
## Residuals:
## Min 1Q Median 3Q Max
## -60.754 -3.569 5.542 13.355 29.083
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 58.5146 2.1788 26.856 <2e-16 ***
## Tempo_BPM 0.0113 0.0177 0.639 0.523
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 21.34 on 1998 degrees of freedom
## Multiple R-squared: 0.0002042, Adjusted R-squared: -0.0002962
## F-statistic: 0.408 on 1 and 1998 DF, p-value: 0.5231
Aquí vemos como el tempo de la cancion no tiene por que afectar a su popularidad, ya que la variable no aparece como significativa.
duracion<-spotify %>% select(Artista,Cancion,Popularidad_cancion,Duracion_segundos) %>% group_by(Popularidad_cancion) %>% arrange(desc(Popularidad_cancion))
duracion
## # A tibble: 2,000 × 4
## # Groups: Popularidad_cancion [76]
## Artista Cancion Popularidad_cancion Duracion_segundos
## <chr> <chr> <int> <dbl>
## 1 The Neighbourhood Sweater Weather 89 240.
## 2 Tom Odell Another Love 88 244.
## 3 Eminem Without Me 87 290.
## 4 Eminem The Real Slim Shady 86 284.
## 5 WILLOW Wait a Minute! 86 197.
## 6 Billie Eilish lovely (with Khalid) 86 200.
## 7 Billie Eilish lovely (with Khalid) 86 200.
## 8 Eminem 'Till I Collapse 85 298.
## 9 Bruno Mars Locked out of Heaven 85 233.
## 10 Bruno Mars Locked out of Heaven 85 233.
## # … with 1,990 more rows
modelo <- lm(Popularidad_cancion ~Duracion_segundos+Contenido_explicito+Tempo_BPM+Capacidad_ser_bailada+Presencia_de_palabras+Intensidad_Actividad, data =spotify)
summary(modelo)
##
## Call:
## lm(formula = Popularidad_cancion ~ Duracion_segundos + Contenido_explicito +
## Tempo_BPM + Capacidad_ser_bailada + Presencia_de_palabras +
## Intensidad_Actividad, data = spotify)
##
## Residuals:
## Min 1Q Median 3Q Max
## -63.341 -3.818 5.614 13.354 29.365
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 54.03274 5.21915 10.353 <2e-16 ***
## Duracion_segundos 0.02436 0.01237 1.969 0.0491 *
## Contenido_explicitoTrue 1.99530 1.22157 1.633 0.1025
## Tempo_BPM 0.01135 0.01824 0.622 0.5338
## Capacidad_ser_bailada -1.46174 3.59497 -0.407 0.6843
## Presencia_de_palabras 0.20137 5.47705 0.037 0.9707
## Intensidad_Actividad -0.95920 3.21227 -0.299 0.7653
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 21.32 on 1993 degrees of freedom
## Multiple R-squared: 0.004564, Adjusted R-squared: 0.001567
## F-statistic: 1.523 on 6 and 1993 DF, p-value: 0.1666
Aquí vemos como la unica variable que se podria tener una relacion significante con la popularidad es la duracion de los segundos.
modelo_intensidad<-lm(Intensidad_Actividad~Duracion_segundos+Contenido_explicito+Tempo_BPM+Capacidad_ser_bailada+Presencia_de_palabras, data =spotify)
summary(modelo_intensidad)
##
## Call:
## lm(formula = Intensidad_Actividad ~ Duracion_segundos + Contenido_explicito +
## Tempo_BPM + Capacidad_ser_bailada + Presencia_de_palabras,
## data = spotify)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.74540 -0.09330 0.01616 0.11294 0.31644
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.211e-01 3.261e-02 22.114 < 2e-16 ***
## Duracion_segundos -2.323e-04 8.611e-05 -2.698 0.00703 **
## Contenido_explicitoTrue -5.076e-02 8.440e-03 -6.015 2.14e-09 ***
## Tempo_BPM 8.241e-04 1.258e-04 6.549 7.33e-11 ***
## Capacidad_ser_bailada -5.057e-02 2.504e-02 -2.020 0.04352 *
## Presencia_de_palabras 1.162e-02 3.818e-02 0.304 0.76084
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1486 on 1994 degrees of freedom
## Multiple R-squared: 0.0556, Adjusted R-squared: 0.05323
## F-statistic: 23.48 on 5 and 1994 DF, p-value: < 2.2e-16
Aquí podemos ver como el tempo y la aparacicion de contenido explicito son muy significativas , junto con la duracion y la capacidad para ser bailadas , pero en menor medida.
Para esto primero calculamos tanto el tempo medio comomla popularidad media por género.
generos_BPM<-spotify %>% select(Genero,Tempo_BPM,Popularidad_cancion) %>% group_by(Genero) %>% summarise(BPM_medio=mean(Tempo_BPM),Popularidad_media=mean(Popularidad_cancion))
generos_BPM
## # A tibble: 59 × 3
## Genero BPM_medio Popularidad_media
## <chr> <dbl> <dbl>
## 1 country 137. 53
## 2 country, latin 96.1 0
## 3 Dance/Electronic 126. 51.8
## 4 easy listening 158. 72
## 5 Folk/Acoustic, pop 112. 78
## 6 Folk/Acoustic, rock 84.2 0
## 7 Folk/Acoustic, rock, pop 139. 68
## 8 hip hop 117. 64.3
## 9 hip hop, country 98.0 69
## 10 hip hop, Dance/Electronic 137. 60.6
## # … with 49 more rows
Grafico_tempo_pop<-ggplot(data =generos_BPM, mapping = aes(x = BPM_medio, y = Popularidad_media, color=Genero)) +
geom_point()+guides(color = guide_legend(override.aes = list(size=0), title.position = "rigth"))
ggplotly(Grafico_tempo_pop)